package com.ctvit.cch.web.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ctvit.cch.core.pojo.dto.creative.CreativeTopicApprovedDTO;
import com.ctvit.cch.core.pojo.dto.creative.CreativeTopicEditDTO;
import com.ctvit.cch.core.pojo.dto.creative.CreativeTopicMyDTO;
import com.ctvit.cch.core.pojo.dto.creative.CreativeTopicPendingDTO;
import com.ctvit.cch.core.pojo.dto.creative.CreativeTopicReSubmitDTO;
import com.ctvit.cch.core.pojo.dto.creative.CreativeTopicSubmitDTO;
import com.ctvit.cch.core.service.ICreativeTopicService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 创意选题Controller
 *
 * @author heyingcheng
 * @date 2025/7/19
 */
@RestController
@RequestMapping("/creative/topic")
public class CreativeTopicController extends BaseController {

    private final ICreativeTopicService creativeTopicService;

    public CreativeTopicController(ICreativeTopicService creativeTopicService) {
        this.creativeTopicService = creativeTopicService;
    }

    /**
     * 查询待审批创意选题列表
     *
     * @return {@link AjaxResult} 待审批列表数据
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:pending')")
    @PostMapping("/pending")
    public TableDataInfo pendingList(@RequestBody @Validated CreativeTopicPendingDTO dto) {
        startPage(dto.getPageNum(), dto.getPageSize());
        return getDataTable(creativeTopicService.getPendingList(dto));
    }

    /**
     * 查询已审批创意选题列表
     *
     * @return {@link AjaxResult} 已审批列表数据
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:approved')")
    @PostMapping("/approved")
    public TableDataInfo approvedList(@RequestBody @Validated CreativeTopicApprovedDTO dto) {
        startPage(dto.getPageNum(), dto.getPageSize());
        return getDataTable(creativeTopicService.getApprovedList(dto));
    }

    /**
     * 查询我的创意选题列表
     *
     * @return {@link AjaxResult} 我的选题列表数据
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:my')")
    @PostMapping("/my")
    public TableDataInfo myList(@RequestBody @Validated CreativeTopicMyDTO dto) {
        startPage(dto.getPageNum(), dto.getPageSize());
        return getDataTable(creativeTopicService.getMyList(dto));
    }

    /**
     * 提交创意选题
     *
     * @param dto 创意选题信息
     * @return {@link AjaxResult} 操作结果
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:submit')")
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody @Validated CreativeTopicSubmitDTO dto) {
        return toAjax(creativeTopicService.submit(dto));
    }

    /**
     * 重新提交创意选题
     *
     * @param dto 创意选题信息
     * @return {@link AjaxResult} 操作结果
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:submit')")
    @PostMapping("/resubmit")
    public AjaxResult reSubmit(@RequestBody @Validated CreativeTopicReSubmitDTO dto) {
        return toAjax(creativeTopicService.reSubmit(dto));
    }

    /**
     * 编辑创意选题
     * 
     * @param dto 创意选题信息
     * @return {@link AjaxResult} 操作结果
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:edit')")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Validated CreativeTopicEditDTO dto) {
        return toAjax(creativeTopicService.edit(dto));
    }

    /**
     * 撤回创意选题
     *
     * @param topicId 创意选题ID
     * @return {@link AjaxResult} 操作结果
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:withdraw')")
    @PostMapping("/withdraw")
    public AjaxResult withdraw(@RequestParam String id) {
        return toAjax(creativeTopicService.withdraw(id));
    }

    /**
     * 删除创意选题
     *
     * @param ids ID列表
     * @return {@link AjaxResult} 删除结果
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:delete')")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody List<String> ids) {
        return toAjax(creativeTopicService.deleteBatchByIds(ids));
    }

    /**
     * 获取创意选题详细信息
     *
     * @param id 创意选题ID
     * @return {@link AjaxResult} 创意选题详细信息
     */
    @PreAuthorize("@ss.hasPermi('creative:topic:get')")
    @PostMapping("/get")
    public AjaxResult get(@RequestParam String id) {
        return AjaxResult.success(creativeTopicService.get(id));
    }

}